home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / tk / tkscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.5 KB  |  271 lines

  1. /* Tk panel stuff.
  2.    Copyright (C) 1995 Miguel de Icaza
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19. #include "fs.h"
  20. #include "dir.h"
  21. #include "tkmain.h"
  22. #include "panel.h"
  23. #include "command.h"
  24. #include "panel.h"        /* current_panel */
  25. #include "command.h"        /* cmdline */
  26. #include "main.h"
  27. #include "mouse.h"
  28. #include "layout.h"        /* get_panel_widget */
  29.  
  30. void do_enter (WPanel *panel);
  31.  
  32. static char *attrib;
  33.  
  34. void set_attr (int h, int m)
  35. {
  36. }
  37.  
  38. void repaint_file (WPanel *panel, int file_index, int move)
  39. {
  40. }
  41.  
  42. void show_dir (WPanel *panel)
  43. {
  44.     char *tkw = wtk_win (panel->widget);
  45.     
  46.     tk_evalf ("%s.cwd configure -text {%s}", tkw, panel->cwd);
  47. }
  48.  
  49. void x_fill_panel (WPanel *panel)
  50. {
  51.     const int top = panel->count;
  52.     char  *panel_name, *tag;
  53.     char  buffer [255];
  54.     int i;
  55.     int selected;
  56.     
  57.     if (!panel->widget.wcontainer)
  58.     return;
  59.  
  60.     selected = panel->selected;
  61.     
  62.     panel_name = copy_strings (wtk_win (panel->widget), ".m.panel", 0);
  63.  
  64.     tk_evalf ("%s delete 0.0 end", panel_name);
  65.     for (i = 0; i < top; i++){
  66.     int marked = panel->dir.list [i].f.marked;
  67.     
  68.     /* FIXME: What is that 39 doing there? */
  69.     format_file (buffer, panel, i, 39);
  70.  
  71.     if (i)
  72.         tk_evalf ("%s insert end \\n", panel_name);
  73.  
  74.     
  75.     /* Set the mark tag name */
  76.     tag = marked ? "ma" : "re";
  77.     
  78.     tk_evalf ("%s insert end {%s} %s", panel_name, buffer, tag);
  79.     }
  80.     if (panel->active)
  81.     x_select_item (panel);
  82. #if 0
  83.     /* The first time, the panel does not yet have a command */
  84.     if (panel->widget.wdata)
  85.     x_select_item (panel);
  86.     free (panel_name);
  87. #endif
  88. }
  89.  
  90. void x_panel_set_size (int index)
  91. {
  92.     Widget *w;
  93.     char *pn;
  94.     static old_width, old_height;
  95.     int width, height;
  96.     
  97.     w = (Widget *) get_panel_widget (index);
  98.     
  99.     tk_evalf ("panel_width");
  100.     width = atoi (interp->result);
  101.     
  102.     tk_evalf ("panel_height");
  103.     height = atoi (interp->result);
  104.  
  105.     if (w && w->cols && w->lines)
  106.     if ((width == old_width) && (height == old_height))
  107.         return;
  108.  
  109.     if ((width < 10) || (height < 3))
  110.     return;
  111.     
  112.     old_width = width;
  113.     old_height = height ;
  114.  
  115.     w = get_panel_widget (index);
  116.     w->cols = width;
  117.     w->lines = height;
  118.  
  119.     panel_update_format ((WPanel *) w);
  120.     x_fill_panel ((WPanel *) w);
  121. }
  122.  
  123. x_change_size (char *panel)
  124. {
  125.     if (strncmp (panel, ".left", 5) == 0)
  126.     x_panel_set_size (0);
  127.     else
  128.     x_panel_set_size (1);
  129. }
  130.  
  131. static char compute_font_size (char *font, char *win, char *dest)
  132. {
  133.     Tk_Uid    font_uid;
  134.     Tk_Window window_id;
  135.     XFontStruct *f;
  136.     int width, height;
  137.     
  138.     font_uid = Tk_GetUid (font);
  139.     window_id = Tk_NameToWindow (interp, win, Tk_MainWindow (interp));
  140.     if (window_id == NULL){
  141.     fprintf (stderr, "Error: %s\n\r", interp->result);
  142.     exit (1);
  143.     }
  144.     f = Tk_GetFontStruct (interp, window_id, font_uid);
  145.  
  146.     if (f == NULL){
  147.     fprintf (stderr, "This should not happend: %s\n", interp->result);
  148.     exit (1);
  149.     }
  150.  
  151.     width = f->max_bounds.width;
  152.     height = f->ascent + f->descent;
  153.  
  154.     /* Ok, we will use this dummy until monday, the correct thing
  155.      * to do is extract the Tk font information from Tk's hash
  156.      * table (tkFont.c).
  157.      *
  158.      * TkFont->widths ['0'] holds the width
  159.      */
  160.     sprintf (dest, "%d %d", height, width);
  161.     Tk_FreeFontStruct (f);
  162. }
  163.  
  164. int tk_panel_callback (ClientData cd, Tcl_Interp *interp, int ac, char *av[])
  165. {
  166.     Gpm_Event e;
  167.     WPanel *panel = (WPanel *) cd;
  168.     char b [20];
  169.     char *p;
  170.     int  mouse_etype = 0;
  171.     
  172.     p = av [1];
  173.     
  174.     if (STREQ (p, "mdown"))
  175.     mouse_etype = GPM_DOWN;
  176.     else if (STREQ (p, "mup"))
  177.     mouse_etype = GPM_UP;
  178.     else if (STREQ (p, "double"))
  179.     mouse_etype = GPM_DOUBLE|GPM_UP;
  180.     else if (STREQ (p,  "motion"))
  181.     mouse_etype = GPM_MOVE|GPM_DRAG;
  182.     else if (STREQ (p, "resize")){
  183.     x_change_size (av [2]);
  184.     return TCL_OK;
  185.     } else if (STREQ (p, "fontdim")){
  186.     compute_font_size (av [2], av [3], interp->result);
  187.     return TCL_OK;
  188.     }
  189.  
  190.     if (STREQ (p, "top")){
  191.     int old_sel = panel->selected;
  192.     int new = old_sel;
  193.     
  194.     panel->top_file = atoi (av [2]) - 1;
  195.     if (old_sel < panel->top_file)
  196.         new = panel->top_file;
  197.     if (old_sel > (panel->top_file + ITEMS (panel)))
  198.         new = panel->top_file + ITEMS (panel) - 1;
  199.     
  200.     if (new != old_sel){
  201.         unselect_item (panel);
  202.         panel->selected = new;
  203.         select_item (panel);
  204.     }
  205.     return TCL_OK;
  206.     }
  207.     
  208.     if (mouse_etype){
  209.     for (p = av [3]; *p && *p != '.'; p++)
  210.         ;
  211.     *p++ = 0;
  212.     e.buttons = (1 << (atoi (av [2]) - 1));
  213.         e.y = atoi (av [3]) + 2 - panel->top_file;
  214.     e.x = atoi (p);
  215.     e.type = mouse_etype;
  216.     panel_event (&e, panel);
  217.     } else {
  218.     /* We are currently dealing with those */
  219.     fprintf (stderr, "Unknown command: %s\n", p);
  220.     return TCL_ERROR;
  221.     }
  222.     return TCL_OK;
  223. }
  224.  
  225. int x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
  226. {
  227.     char *cmd;
  228.     char *container = (char *) panel->widget.wcontainer;
  229.     
  230.     cmd = tk_new_command  (container, panel, tk_panel_callback, 'p');
  231.     tk_evalf ("panel_setup %s", wtk_win (panel->widget));
  232.     tk_evalf ("panel_bind %s %s", wtk_win (panel->widget), cmd);
  233.     x_fill_panel (panel);
  234. }
  235.  
  236. /* Called when f.marked has changed on a file */
  237. void x_panel_select_item (WPanel *panel, int index, int value)
  238. {
  239.     char *s;
  240.  
  241.     s = value ? "add" : "remove";
  242.     tk_evalf ("%s.m.panel tag %s ma %d.0 {%d.0 lineend}", 
  243.         wtk_win (panel->widget), s, index+1, index+1);
  244. }
  245.  
  246. void x_unselect_item (WPanel *panel)
  247. {
  248.     const int selected = panel->selected + 1;
  249.     
  250.     tk_evalf ("%s.m.panel tag remove se %d.0 {%d.0 lineend}",
  251.         wtk_win (panel->widget), selected, selected);
  252. }
  253.  
  254. void x_select_item (WPanel *panel)
  255. {
  256.     const int selected = panel->selected + 1;
  257.     char *cmd = wtcl_cmd (panel->widget);
  258.  
  259.     if (!(cmd && *cmd))
  260.     return;
  261.     
  262.     tk_evalf ("panel_select %s %d %s", wtk_win (panel->widget),
  263.         selected, cmd);
  264. }
  265.  
  266. void x_adjust_top_file (WPanel *panel)
  267. {
  268.     tk_evalf ("%s.m.panel yview %d.0", wtk_win (panel->widget),
  269.          panel->top_file+1);
  270. }
  271.